package com.hy.controller;

import com.hy.grace.result.GraceJSONResult;
import com.hy.pojo.Interviewer;
import com.hy.pojo.bo.InterviewerBO;
import com.hy.service.InterviewerService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/interviewer")
public class InterviewerController {

    @Autowired
    private InterviewerService interviewerService;

    /**
     * 创建或更新面试官
     * @param interviewerBO
     * @return
     */
    @PostMapping("/createOrUpdate")
    // @Valid 校验面试官信息
    public GraceJSONResult createOrUpdate(@Valid @RequestBody InterviewerBO interviewerBO) {
        interviewerService.createOrUpdate(interviewerBO);
        return GraceJSONResult.ok();
    }

    /**
     * 查询所有面试官
     * @return
     */
    @GetMapping("/list")
    public GraceJSONResult list() {
        List<Interviewer> interviewerList = interviewerService.queryAll();
        return GraceJSONResult.ok(interviewerList);
    }

    /**
     * 删除面试官
     * @param interviewerId
     * @return
     */
    @DeleteMapping("/delete")
    public GraceJSONResult delete(@RequestParam String interviewerId) {
        interviewerService.deleteById(interviewerId);
        return GraceJSONResult.ok();
    }
}
